package com.yc.hwc;

import javax.annotation.Resource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.yc.hwc.dao.SqlDao;
import com.yc.hwc.web.util.LoginInterceptor;
import com.yc.hwc.web.util.PubInterceptor;
import com.yc.hwc.web.util.StringToTimestampConverter;

@SpringBootApplication
@ServletComponentScan(basePackages = "com.yc.hwc.web")
public class IndexApplication implements WebMvcConfigurer {

	public static void main(String[] args) {
		SpringApplication.run(IndexApplication.class, args);
	}
	
	/**
	 * disable SerializationFeature.FAIL_ON_EMPTY_BEANS 关于springBoot序列化问题
	 * https://blog.csdn.net/qq_36542152/article/details/85115279
	 * @return
	 */
	@Bean
	public ObjectMapper objectMapper() {
		return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
	}
	
	@Bean
	public SqlDao geSqlDao() {
		return new SqlDao();
	}

	@Resource
	LoginInterceptor li;
	@Resource
	PubInterceptor pi;
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(pi).addPathPatterns("/**");
		registry.addInterceptor(li).addPathPatterns(
				"/to_reply","/to_commit","/to_mylist",
				"/to_tasklog","/to_tasklogs","/to_setpwd",
				"/to_task-edit","/to_myinfo");
	}

	@Override
	public void addFormatters(FormatterRegistry registry) {
		registry.addConverter(new StringToTimestampConverter());
	}
	
	
	
}
